package com.lineage.data.item_etcitem.reel;

import com.lineage.data.cmd.EnchantArmor;
import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;

public class Enc_Percentage_Hundred extends ItemExecutor {
  public static ItemExecutor get() {
    return new Enc_Percentage_Hundred();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    int targObjId = data[0];
    L1ItemInstance tgItem = pc.getInventory().getItem(targObjId);
    if (tgItem == null)
      return; 
    if (tgItem.isEquipped()) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("(预防误点机制启动)装备中无法强化"));
      return;
    } 
    if (tgItem.isSeal()) {
      pc.sendPackets((ServerBasePacket)new S_SystemMessage(String.valueOf(tgItem.getLogName()) + "处于绑定状态！"));
      return;
    } 
    int safe_enchant = tgItem.getItem().get_safeenchant();
    boolean isErr = false;
    int use_type = tgItem.getItem().getUseType();
    switch (use_type) {
      case 23:
      case 24:
      case 37:
      case 40:
        if (tgItem.getItem().get_greater() == 3)
          isErr = true; 
        if (safe_enchant < 0)
          isErr = true; 
        break;
      default:
        isErr = true;
        break;
    } 
    if (tgItem.getBless() >= 128)
      isErr = true; 
    if (isErr) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(79));
      return;
    } 
    int enchant_level = tgItem.getEnchantLevel();
    if (enchant_level >= 9) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(79));
      return;
    } 
    EnchantArmor enchantArmor = new EnchantArmor();
    pc.getInventory().removeItem(item, 1L);
    enchantArmor.successEnchant(pc, tgItem, 1);
  }
}
